package com.navinfo.opentsp.qingqi.trackoptimize.handler;

import com.navinfo.opentsp.qingqi.trackoptimize.commands.QueryTripDetailCommand;
import com.navinfo.opentsp.qingqi.trackoptimize.common.handler.BaseAbstractHandler;
import com.navinfo.opentsp.qingqi.trackoptimize.common.result.HttpCommandResultWithData;
import com.navinfo.opentsp.qingqi.trackoptimize.common.result.ReturnCode;
import com.navinfo.opentsp.qingqi.trackoptimize.service.TripQueryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 查询行程详情handler
*/
@Component
public class QueryTripDetailHandler extends BaseAbstractHandler<QueryTripDetailCommand, HttpCommandResultWithData> {

    protected static final Logger logger = LoggerFactory.getLogger(QueryTripDetailHandler.class);

    @Autowired
    private TripQueryService tripQueryService;

    public QueryTripDetailHandler() {
        super(QueryTripDetailCommand.class, HttpCommandResultWithData.class);
    }

    protected QueryTripDetailHandler(Class<QueryTripDetailCommand> commandType, Class<HttpCommandResultWithData> resultType) {
        super(commandType, resultType);
    }

    public HttpCommandResultWithData businessHandle(QueryTripDetailCommand command)
    {
        logger.info("businessHandle start");
        logger.info(command.toString());
        // 设置返回类型
        HttpCommandResultWithData result = new HttpCommandResultWithData();
        try
        {
//            Map map = new HashMap();
//            map.put("data",tripQueryService.queryTripInfo(command));
           result.setData(tripQueryService.queryTripInfo(command));
            result.fillResult(ReturnCode.OK);
        }
        catch (Exception e)
        {
            result.fillResult(ReturnCode.SERVER_ERROR);
            logger.error("businessHandle ", e);
        }
        logger.info("businessHandle end");
        return result;
    }

}
